import {Component} from '@angular/core';
import {Http, Response} from '@angular/http';

@Component({
	selector:'http-demo',
	template:`
		<h2>Basic Request</h2>	
		<button (click)="makeRequest()">MakeRequest</button>
		<div *ngIf="loading">loading...</div>
		<pre>{{data|json}}</pre>
	`
})
export class HttpSimpleRequest{
	data: Object;
	loading: boolean;
	constructor(public http:Http){
		/*the same to follow*/
		/*
			http: Http;
			constructor(http: Http) {
			this.http = http;
			}
		*/

	}
	makeRequest():void{
		this.loading = true;
		this.http.request('http://jsonplaceholder.typicode.com/posts/1')
			.subscribe((res: Response) => {
				this.data = res.json;
				this.loading = false;
			});
	}
}